package com.blog.controller.adminannouncement;

import java.io.IOException;
import java.sql.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.blog.controller.base.BaseServlet;
import com.blog.entity.NoticeEntity;
import com.blog.service.adminannouncement.AdminNoticeService;
import com.blog.utils.TimeUtils;

@WebServlet("/adminAddNotice")
public class AdminAddNoticeServlet extends BaseServlet {

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// 获得数据
		String title = req.getParameter("title");
		String person = req.getParameter("person");
		String str = req.getParameter("time");
		String content = req.getParameter("content");
		String status = req.getParameter("status");
		Date strToDate = null;
		if (str != null&&!title.isEmpty()) {
			TimeUtils timeUtils = new TimeUtils();
			strToDate = timeUtils.strToDate(str);
		}
		NoticeEntity notice = new NoticeEntity();
		if(title!=null&&!title.isEmpty()) {
			notice.setNotice_title(title);
		}
			notice.setNotice_time(strToDate);
		if (person != null&&!title.isEmpty()) {
			notice.setNotice_personid(person);
		}
		if (content != null&&!content.isEmpty()) {
			notice.setNotice_content(content);
		}
		if (status != null&&!title.isEmpty()) {
			if (status.equals("确认发表")) {
				notice.setNotic_status(0);
			}
			if (status.equals("存为草稿")) {
				notice.setNotic_status(1);
			}

		}
		// 添加公告
		AdminNoticeService service = new AdminNoticeService();
		int addNotice = service.addNotice(notice);
		/*
		 * if(addNotice>0) { req.setAttribute("info", "操作成功！"); }
		 */
		forward("admin/addnotice");
	}
}
